package mka.puzzle.form;

import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import mka.puzzle.cartesian.Axis;
import mka.puzzle.draw.PaintShape;
import mka.puzzle.draw.Painter;
import mka.puzzle.shape.Circle;
import mka.puzzle.shape.Line;
import mka.puzzle.shape.Point;
import mka.puzzle.shape.Rectangle;
import mka.puzzle.shape.Shape;
import mka.puzzle.shape.ShapeList;
import mka.puzzle.shape.Square;
import mka.puzzle.util.Function;

public class Form2 extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				createAndShowGUI();
			}
		});
	}

	private static void createAndShowGUI() {
		// System.out.println("Created GUI on EDT? "
		// + SwingUtilities.isEventDispatchThread());
		SwingUtilities.isEventDispatchThread();

		ShapeList shapeList = new ShapeList();

		Painter paint = new Painter();

		int number = 100;

		// Random Add Element
		for (int i = 0; i < number; i++) {
			Function.addRandomShape(shapeList);
		}

		// Before the graphics are drawn on frame
		long timeBefore = System.currentTimeMillis();
		for (Shape shape : shapeList.getShapeList()) {
			paint.addPointList(shape.allPointBound());
		}
		// Point c = new Point(400, 300);
		// Circle oc = new Circle(c, 200);
		// // paint.addPointList(oc.allPointShape3());
		//
		// Point p = new Point(800, 100);
		// Square s = new Square(p, 200);
		// paint.addPointList(s.allPointShape());

		// Line line = new Line(new Point(100, 250), new Point(100, 100));
		// paint.addPointList(line.allPointLine());

		// Line line = new Line(new Point(100, 200), new Point(600, 0));
		// // paint.addPointList(line.allPointBresenham());
		//
		// Point c1 = new Point(200, 200);
		// Point c2 = new Point(300, 300);
		// Rectangle re = new Rectangle(c1, 300, 100);
		// paint.addPointList(re.allPointBound());

//		Axis axis = new Axis(800);
		// paint.addPointList(axis.getAxisX().allPointLine());
		// paint.addPointList(axis.getAxisY().allPointLine());

		JFrame f = new JFrame("Graphic Puzzle");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setPreferredSize(new Dimension(1000, 700));
		f.setLocation(50, 50);
		f.setResizable(false);
		f.add(paint);
		f.pack();
		f.setVisible(true);

		// After the graphics are drawn on frame
		long timeAfter = System.currentTimeMillis();

		System.out.println("Time process: " + (timeAfter - timeBefore) + "s");
	}
}
